package com.longge.wechat.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;


import com.longge.wechat.dao.BaseDao;
import com.longge.wechat.dao.UserMessageDao;
import com.longge.wechat.entity.UserMessageEntity;

@Repository
public class UserMessageDaoImpl extends BaseDao<UserMessageEntity> implements UserMessageDao {

	@Override
	public void saveUserMessage(UserMessageEntity ume) {
		super.save(ume);
	}

	@Override
	public void updateUserMessage(UserMessageEntity ume) {
		super.update(ume);
	}

	@Override
	public UserMessageEntity findUserMessageByOpenId(String openId) {
		Query q = createQuery("from UserMessageEntity u where u.openId =? order by u.id desc", openId);
		q.setMaxResults(1);
		return (UserMessageEntity)q.uniqueResult();
	}

	@Override
	public List<UserMessageEntity> findAllUserMessage(int pageSize, int currentPage) {
		String hql = "from UserMessageEntity";
		return super.getObjects(pageSize, currentPage, hql);
	}
}
